﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace CRPTModularCorrousel
{
    public class ModularTemplate : ITemplate
    {
        private const string STYLE_BACKGROUND = "background-image: url({0});background-size: 965px 400px;";

        [Browsable(true)]
        [Category("Behavior")]
        public string ImageUrl{ get; set;}

        [Browsable(true)]
        [Category("Behavior")]
        public string ParagraphText { get; set; }

        public void InstantiateIn(Control container)
        {            
            var li = new HtmlGenericControl("li");
            var paragraph = new HtmlGenericControl("p");
            if (!String.IsNullOrEmpty(ParagraphText)) {
                paragraph.InnerText = ParagraphText;
            }
            if (!String.IsNullOrEmpty(ImageUrl)) { 
                paragraph.Attributes.Add("style", String.Format(STYLE_BACKGROUND, ImageUrl));
            }
            li.Controls.Add(paragraph);
            container.Controls.Add(li);
        }
    }
}
